#!/usr/bin/env python3
# Created by han on 2016/6/9
import os,sys,platform
if platform.system() == 'Windows':
    BASE_DIR = '\\'.join(os.path.dirname(__file__).split('/')[:-1])
else:
    BASE_DIR = '/'.join(os.path.dirname(__file__).split('/')[:-1])
sys.path.append(BASE_DIR)

from module import public,shop_conf
from conf import db_conf


def main():
    while True:
        frist_page = ["用户登陆","用户注册"]
        msg = "欢迎光临京北商城".center(40," ")
        public.color_msg(32,msg)
        user_inp = public.user_chose(*frist_page)
        if user_inp == "1":
            user_dict = shop_conf.login_info()
            if user_dict:
                while True:
                    second_page = ["选购商品","查看购物车","购买记录"]
                    user_inp = public.user_chose(*second_page)
                    if user_inp == "1":
                        while True:
                           shop_name = shop_conf.shop(**user_dict)
                           #print(shop_name)
                           if shop_name:
                               new_buy_dict = shop_conf.buy_car(*shop_name,**user_dict)
                               if new_buy_dict:                                                     #因为使用了装饰器，一旦走到了装饰器里这里就是None了
                                   public.save_shop_file(new_buy_dict[0],**new_buy_dict[1])         #添加物品到购物车里
                           else:
                                break
                    elif user_inp == "2":                                                           #查看购物车
                        new_user_dict = shop_conf.check_car(**user_dict)                            #
                        shop_conf.pay(**new_user_dict)
                    elif user_inp == "3":                                                           #查看购买记录
                        shop_conf.check_pay(**user_dict)
                    elif user_inp == "0":
                        break
                    else:
                        msg = "输入有误请重新输入： ".center(40," ")
                        public.color_msg(31,msg)
            else:
                continue
        elif user_inp == "2":
            shop_conf.register()








if __name__ == '__main__':
    main()